﻿using System.Windows;
using Microsoft.Xna.Framework;

namespace Silverlight3dApp.Recipes.Chapter01.Lesson01
{
    public class Camera : GameComponent
    {
        protected Matrix _View;
        protected Matrix _Projection;

        public Matrix View
        {
            get
            {
                return _View;
            }
        }

        public Matrix Projection
        {
            get
            {
                return _Projection;
            }
        }

        public Camera(Game game, Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector) : base(game)
        {
            game.Window.SizeChanged += WindowOnSizeChanged;
            _View = Matrix.CreateLookAt(cameraPosition, cameraTarget, cameraUpVector);
        }

        private void WindowOnSizeChanged(object sender, SizeChangedEventArgs e)
        {
            _Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float) (e.NewSize.Width / e.NewSize.Height), 1.0f, 100f);
        }
    }
}